package com.software.graduationproject.modules.sys.web;

import com.baomidou.mybatisplus.core.metadata.Page;
import com.software.graduationproject.commons.util.Result;
import com.software.graduationproject.commons.util.Results;
import com.software.graduationproject.modules.sys.entity.SysRole;
import com.software.graduationproject.modules.sys.object.SysRoleVo;
import com.software.graduationproject.modules.sys.service.SysRoleService;
import com.software.graduationproject.modules.sys.object.SysRoleCreateQo;
import com.software.graduationproject.modules.sys.object.SysRoleUpdateQo;

import com.v2coding.validate.CreateGroup;
import com.v2coding.validate.UpdateGroup;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * SysRoleController : 角色
 * ---------------------------------------------------------------------------------------------------------------------
 */
@Validated
@RestController
@RequestMapping("/Sys/SysRole")
@Api(value = "API - 角色", tags = {"角色接口"})
public class SysRoleController {

    @Autowired
    private SysRoleService sysRoleService;

//    @PostMapping("/create")
//    @ApiOperation("新增角色")
//    public Result createQo(@RequestBody @Validated(CreateGroup.class) SysRoleCreateQo qo) {
//        sysRoleService.createQo(qo);
//        return Results.success();
//    }
//
//    @PostMapping("/update")
//    @ApiOperation("修改角色")
//    public Result updateQo(@RequestBody @Validated(UpdateGroup.class) SysRoleUpdateQo qo) {
//        sysRoleService.updateQo(qo);
//        return Results.success();
//    }
//
//    @PostMapping("/delete")
//    @ApiOperation("删除角色")
//    public Result delete(@RequestBody Long id) {
//        sysRoleService.delete(id);
//        return Results.success();
//    }
//
//    @PostMapping("/deleteList")
//    @ApiOperation("批量删除角色")
//    public Result deleteList(@RequestBody Long []ids) {
//        sysRoleService.deleteList(ids);
//        return Results.success();
//    }
//
//    @GetMapping("/select")
//    @ApiOperation("查询角色详情")
//    public Result<SysRoleVo> selectVo(Long id) {
//        SysRoleVo sysRoleVo = sysRoleService.selectVo(id);
//        return Results.success(sysRoleVo);
//    }

    @GetMapping("/selectList")
    @ApiOperation("查询角色列表")
    public Result<List<SysRoleVo>> selectListVo() {
        List<SysRoleVo> sysRoleVoList = sysRoleService.selectListVo();
        return Results.success(sysRoleVoList);
    }

    @GetMapping("/selectPage")
    @ApiOperation("查询角色分页")
    public Result<Page<SysRoleVo>> selectPageVo() {
        Page<SysRoleVo> sysRoleVoPage = sysRoleService.selectPageVo();
        return Results.success(sysRoleVoPage);
    }

//    @GetMapping("/export")
//    @ApiOperation("导出角色")
//    @SelectParam({"sort.id=desc"})
//    @ApiImplicitParams({ //
//            @ApiImplicitParam(name = "select", value = "查询条件", required = false, dataTypeClass = String.class, paramType = "query"),//
//            @ApiImplicitParam(name = "columns", value = "导出列", required = true, dataTypeClass = String.class, paramType = "query"),//
//    })
//    public void export(@ApiIgnore Select select,@RequestParam(defaultValue = "导出.xls") String title, String columns, String headers) {
//        ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
//        HttpServletResponse response = requestAttributes.getResponse();
//        // @formatter:off
//        Excels.ExportParams params = new Excels.ExportParams()
//                .setList(sysRoleService.selectList(select, SysRoleVo.class))
//                .setClazz(SysRole.class)
//                .setColumns(columns)
//                .setHeaders(headers);
//        // @formatter:on
//        Excels.export(params, response);
//    }

}
